package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class update_class
 */
@WebServlet("/update_class")
public class update_class extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public update_class() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		
		String centername = request.getParameter("centername");
		String classname = request.getParameter("classname");
		// 外教两部分的时间拼接起来
		String ftweek = request.getParameter("ftweek");
		String fttime_start = request.getParameter("fttime_start");
		String fttime_end = request.getParameter("fttime_end");
		String ftime = ftweek + fttime_start + "-" + fttime_end;
		System.out.println(ftime);
		// 中教两部分时间拼接起来
		String ctweek = request.getParameter("ctweek");
		String cttime_start = request.getParameter("cttime_start");
		String cttime_end = request.getParameter("cttime_end");
		String ctime = ctweek + cttime_start + "-" + cttime_end;
		System.out.println(ctime);

		String fteachername = request.getParameter("fteachername");
		String cteachername = request.getParameter("cteachername");
		String classlevel = request.getParameter("classlevel");
		String startdate = request.getParameter("startdate");
		String enddate = request.getParameter("enddate");
		String stunum = request.getParameter("stunum");
		String stunumrest = stunum;
		// 插入SQL语句
//		String insert = "insert into class(centername,classname,fttime,cttime,fteacher,cteacher,classlevel,startdate,enddate,stunum,stunumrest)values("
//				+ "'" + centername + "','" + classname + "','" + ftime + "','" + ctime + "','" + fteachername + "','"
//				+ cteachername + "','" + classlevel + "','" + startdate + "','" + enddate + "','" + stunum + "','"
//				+ stunumrest + "')";
		//更新语句
		String update ="update class set fttime='"+ftime+"', cttime='"+ctime+"',fteacher='"+fteachername+"',cteacher='"+cteachername+"',classlevel='"+classlevel+"',startdate='"+startdate+"',enddate='"+enddate+"' "
				+ "where classname='"+classname+"' and centername='"+centername+"' ";
        System.out.println(update);
		Jdbc j1 = null;
		try {
			j1 = new Jdbc(update);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("showsuccess.jsp").forward(request, response);

	
	}

}
